class UsersController < ApplicationController
before_filter :admin_required, :only => [ :approve, :index, :destroy ]

  # GET /users
  # GET /users.xml
  def index
    @users = User.find(:all)
    respond_to do |format|
      format.html # index.html.erb
      format.js
      format.xml  { render :xml => @arguments }
    end
  end

  # render new.rhtml
  def new
  end

  def create
    cookies.delete :auth_token
    # protects against session fixation attacks, wreaks havoc with 
    # request forgery protection.
    # uncomment at your own risk
    # reset_session
    @user = User.new(params[:user])
    @user.save
    if @user.errors.empty?
      self.current_user = @user
      redirect_back_or_default('/')
      flash[:notice] = "Thanks for signing up!".t
    else
      render :action => 'new'
    end
  end

# uses check_box to toggle translating on and off 
  def translating_toggle_check
    user = User.find(params["id"])
    # change the is_translating state
    user.toggle(:is_translating)
    if user.save
      redirect_to :back
    else
      render :text => "Couldn't change to translate mode".t
    end
  end

  # GET /users/1/approve
  def approve
    user = User.find(params[:id])
    user.is_approved = 1
    if user.save
      flash[:notice] = "User approved.".t
      redirect_to :back
    else
      render :text => "Couldn't approve user.".t
    end
  end

  # DELETE /quotes/1
  # DELETE /quotes/1.xml
  def destroy
    @user = User.find(params[:id])
    @user.destroy

    respond_to do |format|
      format.html { redirect_to(users_url) }
      format.xml  { head :ok }
    end
  end


end
